package gmusic;

import gmusic.ma.bo.ArtistMABean;
import gmusic.ma.bo.ReleaseMABean;
import gmusic.ma.services.impl.MetalArchivesServicesImpl;
import gmusic.services.impl.GMusicServicesImpl;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.List;
import java.util.Properties;

import org.apache.log4j.Logger;
import org.apache.log4j.xml.DOMConfigurator;

import algutil.system.Systeme;

public class Test {

	private static final Logger log = Logger.getLogger(Test.class);

	public static void main(String[] args) throws Exception {
		// try {
		DOMConfigurator.configure("conf/log4j.xml");
		if (Systeme.getOS() == Systeme.WINDOWS_OS) {
			Properties systemProperties = System.getProperties();
			systemProperties.setProperty("http.proxyHost", "172.16.1.138");
			systemProperties.setProperty("http.proxyPort", "3128");
		}

		List<ArtistMABean> artists = MetalArchivesServicesImpl.getInstance()
				.getAllArtists();
		for (int i = 0; i < artists.size(); i++) {
			log.info("A=" + artists.get(i).getNom());
			List<ReleaseMABean> releases = MetalArchivesServicesImpl
					.getInstance().getReleases(artists.get(i).getMaid());
			for (int j = 0; j < releases.size(); j++) {

				if (!new File(GMusicServicesImpl.getInstance().getCoverPath()
						.getPath()
						+ File.separator
						+ "rmaid"
						+ releases.get(j).getMaid()
						+ ".jpg").exists()) {
					log.info("  R=" + releases.get(j).getNom());
					try {
					MetalArchivesServicesImpl.getInstance()
							.saveCoverToLocalhost(releases.get(j));
					} catch (FileNotFoundException e) {
						log.error(e.getMessage());
					}
				}
			}
		}
	}
}
